package com.ce.cases.source.action;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;

import com.ce.cases.check.dao.po.CaseCheckEnterprice;
import com.ce.cases.check.dao.po.CaseSourceCheck;
import com.ce.cases.execute.dao.po.CaseSourceExecute;
import com.ce.cases.hear.dao.po.CaseSourceHear;
import com.ce.cases.source.dao.po.CaseSource;
import com.ce.cases.source.dao.po.CaseSourceApprove;
import com.ce.cases.source.dao.po.CaseSourceDrawApprove;
import com.ce.cases.source.dao.po.CaseSourceFiles;
import com.ce.cases.source.dao.po.CaseSourceFilesTemplate;
import com.ce.cases.source.dao.po.CaseSourceYearNotEnd;
import com.ce.framework.constants.WebConstants;
import com.ce.framework.context.FrameworkContext;
import com.ce.framework.datamaintain.action.DataMaintainAction;
import com.ce.framework.datamaintain.dao.po.AbstractPO;
import com.ce.framework.datamaintain.logic.ISQLMapper;
import com.ce.framework.exception.AppException;
import com.ce.framework.util.BeanAccessUtil;
import com.ce.framework.util.DateUtil;
import com.ce.framework.util.FileUtil;
import com.ce.framework.util.GeneratorUUID;
import com.ce.framework.util.LogUtil;
import com.ce.framework.util.StringUtil;
import com.ce.framework.util.node.JsonTreeNode;
import com.ce.pub.upload.dao.po.PubFileUploadLog;
import com.ce.sys.dict.dao.po.SysDictItem;
import com.ce.sys.login.model.User;
import com.ce.sys.org.dao.po.SysVOrg;
import com.ce.sys.person.dao.po.SysPerson;
import com.ce.util.DbUtil;
import com.ce.util.DictUtil;
import com.ce.util.FlowPicView;
import com.ce.util.FlowWorkUtil;
import com.ce.util.NetFileUtil;
import com.ce.util.OrgUtil;
import com.ce.util.RegeditUtil;
import com.ce.util.TreeNode;
import com.ce.workflow.work.dao.po.WorkflowFlow;
import com.ce.workflow.work.dao.po.WorkflowMan;
import com.ce.workflow.work.dao.po.WorkflowWork;

/**
 * 嫦娥软件有限公司 版权所有 2013 创建人：　andy 
 * 创建日期：2014-03-18 
 * 创建时间：15:29:27 
 * 功能描述：备选案源台账
 * [CASE_SOURCE]更改时用的Action 
 * ============================================== 
 * 修改历史
 * 修改人 修改时间 修改原因 
 * 刘渝洪 2015-05-22 对页面多个细节的修改需求
 * 刘渝洪 2015-06-10 对个人桌面的案件进展情况统计，添加转接案源列
 * ==============================================
 */
public class CaseSourceReceiveAction_2 extends DataMaintainAction {
	private static final long serialVersionUID = 1L;

	private CaseSourceApprove appr;
	private CaseSourceDrawApprove drawAppr;

	@Override
	protected void initOtherData(boolean isNew)
	{
		if (isNew)
		{
			User user = User.getUser();
			String orgLevel = user.getRootOrgLevel();
			try {
				BeanAccessUtil.copyProperty(po, "registerPerson",
						User.getUserName());
				BeanAccessUtil.copyProperty(po, "registerDate", new Date());
				// if("2".equals(orgLevel)){
				// BeanAccessUtil.copyProperty(po, "registerDate", new Date());
				// }
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}
		}
	}

	@Override
	protected String addItem() throws AppException {
		try {
			BeanAccessUtil.copyProperty(po, "registerDeptId",
					User.getUserOrgId());
			BeanAccessUtil.copyProperty(po, "registerDeptName",
					User.getUserOrgName());
			BeanAccessUtil.copyProperty(po, "state", "0");
			BeanAccessUtil.copyProperty(po, "stateInfo", "备选案源");
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return super.addItem();
	}

	@Override
	protected String modifyItem() throws AppException {
		// 避免将流程状态暴漏给页面，避免非法篡改
		AbstractPO entiy = (AbstractPO) this.baselogic.getPOByPk(po.getClass()
				.getName(), po.getVcId());
		BeanAccessUtil.copyNoCopyNullProperty(po, entiy);
		this.baselogic.updatePo(entiy, this.getAddList(), this.getModifyList(),
				this.getDeleteList());
		return super.searchData();
	}

	@Override
	public String look() throws AppException
	{
		super.look();
		return WebConstants.REQUEST_LOOKDATA_OPERATOR;
	}

	// //
	public String openZcdcPage() {
		User user = User.getUser();
		String vcId = this.getParameter("chkSelf");
		this.setAttribute("vcId", vcId);//
		return "openZcdcPage";
	}

	public String saveDcSuccessed() {
		String vcId = this.getParameter("vcId");
		String vcAdvance = this.getParameter("vcAdvance");
		CaseSource po = new CaseSource();
		User user = User.getUser();
		try {
			po = (CaseSource) this.baselogic.getPOByPk(po.getClass().getName(),
					vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		WorkflowWork work = FlowWorkUtil.getWorkflowWork(vcId);
		if (work != null) {
			work.setVcStatus("-2");// 暂存待查
			work.setVcHandleDate(new Date());
			work.setVcHandleInfo(vcAdvance);
			WorkflowFlow flow = FlowWorkUtil.getWorkflowFlowByPerson(vcId,
					user.getUserId());
			if (flow != null) {
				flow.setVcStatus("2");
				try {
					this.baselogic.updatePo(flow);
				} catch (AppException e) {
					e.printStackTrace();
				}
			}

			try {
				this.baselogic.updatePo(work);
			} catch (AppException e) {
				e.printStackTrace();
			}
		}

		FlowWorkUtil.saveWorkflowMan(vcId, vcAdvance);
		return this.returnInfoForJS(true, null);
	}

	/**
	 * &#x91cd;&#x65b0;&#x542f;&#x52a8;
	 *
	 * @return
	 */
	public String saveNewStartSuccessed() {
		String vcId = this.getParameter("chkSelf");
		CaseSource po = new CaseSource();
		User user = User.getUser();
		try {
			po = (CaseSource) this.baselogic.getPOByPk(po.getClass().getName(),
					vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		WorkflowWork work = FlowWorkUtil.getWorkflowWork(vcId);

		WorkflowFlow flow = FlowWorkUtil.getWorkflowFlowByPerson(vcId,
				user.getUserId());
		flow.setVcStatus("1");// 设置为处理中
		work.setVcStatus(flow.getVcSequence().toString());// 设置当前环节。
		work.setVcHandleDate(new Date());
		work.setVcHandleInfo("重启");
		try {
			this.baselogic.updatePo(work);
			this.baselogic.updatePo(flow);
			/*
			 * 2015-05-21 by 刘渝洪，开始 添加代码：对“中止”状态案源的重启处理
			 * 若caseSource.vc_end_type='1'(检查中止)或'3'(执行中止) 重启后，设为'null'（默认初始状态）
			 */
			po.setVcEndType(null);
			this.baselogic.updatePo(po);
			/* 2015-05-21 by 刘渝洪，结束 */
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		FlowWorkUtil.saveWorkflowMan(vcId, "重新启动");
		return this.returnInfoForJS(true, "重启成功！");
	}

	public String saveEndSuccessed() {
		String vcId = this.getParameter("chkSelf");
		CaseSource po = new CaseSource();
		User user = User.getUser();
		try {
			po = (CaseSource) this.baselogic.getPOByPk(po.getClass().getName(),
					vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		po.setEndDate(new Date());
		WorkflowWork work = FlowWorkUtil.getWorkflowWork(vcId);
		/*
		 * 2015-05-20 by 刘渝洪，开始 添加代码：判断若已经结案，则不能重复结案。
		 */
		if ("9".equals(work.getVcStatus())) {
			return this.returnInfoForJS(false, "不能重复结案！");
		}
		/* 2015-05-20 by 刘渝洪，结束 */
		work.setVcStatus("9");// 结案
		work.setVcHandleDate(new Date());
		work.setVcHandleInfo("结案");
		WorkflowFlow flow = FlowWorkUtil.getWorkflowFlowByPerson(vcId,
				user.getUserId());
		flow.setVcStatus("2");
		try {
			this.baselogic.updatePo(work);
			this.baselogic.updatePo(flow);
			this.baselogic.updatePo(po);// 保存结案时间
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		FlowWorkUtil.saveWorkflowMan(vcId, "结案");
		return this.returnInfoForJS(true, "结案成功！");
	}

	public String saveStopSuccessed() {
		String vcId = this.getParameter("chkSelf");
		String vcEndType = this.getParameter("vcEndType");
		CaseSource po = new CaseSource();
		User user = User.getUser();
		try {
			po = (CaseSource) this.baselogic.getPOByPk(po.getClass().getName(),
					vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		po.setVcEndType(vcEndType);
		/*
		 * 2015-05-21 by 刘渝洪，开始
		 * 修改代码：在点击“中止检查”或“中止执行”时，设置T_WORKFLOW_FLOW.vc_status=“2”
		 * 原代码：
		 * try {
		 * this.baselogic.updatePo(po);
		 * }
		 * catch (AppException e) { // TODO
		 * Auto-generated catch block e.printStackTrace(); }
		 */
		WorkflowFlow flow = FlowWorkUtil.getWorkflowFlowByPerson(vcId,user.getUserId());
		flow.setVcStatus("2");
		try {
			if ("1".equals(vcEndType) || "3".equals(vcEndType)) {
				this.baselogic.updatePo(flow);
			}
			this.baselogic.updatePo(po);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		/* 2015-05-21 by 刘渝洪，结束 */
		String endContent = "";
		if ("1".equals(vcEndType))
			endContent = "中止检查";
		else if ("2".equals(vcEndType))
			endContent = "终止检查";
		else if ("3".equals(vcEndType))
			endContent = "中止执行";
		else if ("4".equals(vcEndType))
			endContent = "终止执行";
		FlowWorkUtil.saveWorkflowMan(vcId, endContent);
		return this.returnInfoForJS(true, "操作成功！");
	}

	public String openShPage() {
		User user = User.getUser();
		String vcId = this.getParameter("chkSelf");
		String vcPosition = user.getVcPosition();// 职务
		this.setAttribute("vcId", vcId);//
		this.setAttribute("vcPosition", vcPosition);// 01 局长 02 副局长
		List<SysPerson> persons = OrgUtil.getUserByOrgId("15009070700", true);
		this.setAttribute("persons", persons);
		return "openShPage";
	}

	public String saveShSuccessed() {
		String vcId = this.getParameter("vcId");
		String shFlag = this.getParameter("shFlag");
		String vcAdvance = this.getParameter("vcAdvance");
		CaseSource po = new CaseSource();
		User user = User.getUser();
		String vcPosition = user.getVcPosition();// 职务

		try {
			po = (CaseSource) this.baselogic.getPOByPk(po.getClass().getName(),
					vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		po.setStateInfo(vcAdvance);
		if ("02".equals(vcPosition)) {// 副局
			if ("1".equals(shFlag)) {
				po.setState(2);// 同意
				FlowWorkUtil.updateFlowWork(vcId, "15009070700",
						OrgUtil.getOrgName("15009070700"), "15009030001",
						OrgUtil.getUserName("15009030001"), vcAdvance);
			} else {
				po.setState(-1);// 驳回
				WorkflowWork work = FlowWorkUtil.getWorkflowWork(vcId);
				FlowWorkUtil.updateFlowWork(vcId, work.getVcOrgId(),
						work.getVcOrgName(), work.getVcPersonId(),
						work.getVcPersonName(), vcAdvance);
			}
		} else {// 局长审批
			if ("1".equals(shFlag)) {
				po.setState(3);// 同意
			} else {
				po.setState(-2);// 驳回
			}
			WorkflowWork work = FlowWorkUtil.getWorkflowWork(vcId);
			FlowWorkUtil.updateFlowWork(vcId, work.getVcOrgId(),
					work.getVcOrgName(), work.getVcPersonId(),
					work.getVcPersonName(), vcAdvance);
		}
		try {
			this.baselogic.updatePo(po);
		} catch (AppException e) {
			e.printStackTrace();
		}
		return this.returnInfoForJS(true, null);
	}

	public String lookItemFrame() {

		SysVOrg curorg = OrgUtil.getOrg(User.getUserOrgId());
		this.setAttribute("orgType", curorg.getVcOrgLevel());
		String vcId = this.getParameter("chkSelf");
		CaseSource po = null;
		try {
			po = (CaseSource) this.baselogic.getPOByPk(
					CaseSource.class.getName(), vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		WorkflowWork work = FlowWorkUtil.getWorkflowWork(vcId);
		if (work != null) {
			User user = User.getUser();

			WorkflowFlow flowing = FlowWorkUtil.getWorkflowFlowByPersonCling(
					vcId, user.getUserId());// 当前人正在处理的节点

			WorkflowFlow flow = FlowWorkUtil.getWorkflowFlowByPerson(vcId,
					user.getUserId());
			// 显示同意撤销按钮
			if (user.getVcId().equals(po.getVcDownmanId())
					&& "1".equals(po.getVcRevocation())) {
				this.setAttribute("showShRevocationButton", "true");
			}

			int endType = 0;
			if (flowing != null) {
				if (StringUtil.isNotBlank(po.getVcEndType()))
					endType = Integer.parseInt(po.getVcEndType());
				if (flowing.getVcSequence() == 2) {// 检查环节
					if (endType == 0) {// 中止检查{
						this.setAttribute("showStopCheckButton", "true");
						this.setAttribute("showEndCheckButton", "true");
					}
					if (endType == 1) {
						this.setAttribute("showEndCheckButton", "true");
					}

				}
				if (flowing.getVcSequence() == 4) {// 执行环节
					if (endType == 0) {// 中止检查{
						this.setAttribute("showStopExecButton", "true");
						this.setAttribute("showEndExecButton", "true");
					}
					if (endType == 3) {
						this.setAttribute("showEndExecButton", "true");
					}
				}
			}

			if (user.getVcId().equals(work.getVcHandlePersonId())) {
				/*
				 * 2015-05-20 by 刘渝洪，开始 修改代码：为检查中止和执行中止的案源，添加重启按钮 原代码：
				 * if("-2".equals(work.getVcStatus())){//暂存待查的案件
				 */
				if ("-2".equals(work.getVcStatus())
						|| "1".equals(po.getVcEndType())
						|| "3".equals(po.getVcEndType())) {// 暂存待查、检查中止和执行中止的案件
					/* 2015-05-20 by 刘渝洪，结束 */
					this.setAttribute("showBtnNewButton", "true");
				}
				if (3 == po.getState()
						&& RegeditUtil.getRegeditStringValue("SYSTEM_SEG_ID")
								.equals(user.getRootOrgId())) {// 是否显示审核按钮，案源下发之前，选案科、主管局长、局长的审核步骤。
					this.setAttribute("showBtnDown", "true");// 下发按钮
				}
				if (3 == po.getState()
						&& "3".equals(OrgUtil.getOrg(user.getVcOrgId())
								.getVcOrgLevel())) {// 跨区稽查局科室人员的按钮
					this.setAttribute("showBtnQs", "true");// 签收
					if (flow != null && 1 != flow.getVcSequence().intValue()) {// 选案岗
																				// 撤销操作按钮
						this.setAttribute("showBtnHt", "true");
					}

					this.setAttribute("showBtnYj", "true");
				}

				if ((0 != po.getState())
						&& "15009070700".equals(user.getVcOrgId())) {// 市局局长室审核
					this.setAttribute("showBtnSh", "true");
				}
			}

			if (!"-2".equals(work.getVcStatus())) {// 暂存待查的案件
				if (flow != null && 1 == flow.getVcSequence().intValue()) {// 选案岗
					this.setAttribute("showBtnZcdcButton", "true");
				}

			}
			if (!"9".equals(work.getVcStatus())) {// 未结案 撤销操作按钮
				if (flow != null && 1 == flow.getVcSequence().intValue()) {// 选案岗
																			// 撤销操作按钮
					this.setAttribute("showRevocationButton", "true");
				}
				if (flow != null && 1 == flow.getVcSequence().intValue()) {// 选案岗
																			// 合并操作按钮/
					this.setAttribute("showJoinButton", "true");
				}
			}
			if (flow != null
					&& (4 == flow.getVcSequence() || 3 == flow.getVcSequence())) {
				this.setAttribute("showBtnEnd", "true");
			}
		}
		if (StringUtil.isNotBlank(po.getReportId()))
			this.setAttribute("showBtnReport", "true");

		return "lookItemFrame";
	}

	public void wsTree() {
		String vcRecordId = this.getParameter("vcRecordId");
		User user = User.getUser();
		String hql = "from CaseSourceFiles t where t.vcRecordId='" + vcRecordId
				+ "'";
		WorkflowFlow flow = FlowWorkUtil.getWorkflowFlowByPerson(vcRecordId,
				User.getUserId());
		if ("2".equals(user.getRootOrgLevel()) && flow != null) {
			if ("3".equals(user.getOrgLevel())
					&& ("08".equals(user.getVcPosition())
							|| "09".equals(user.getVcPosition()) || "10"
								.equals(user.getVcPosition()))) {// 库区局科长、副科长、科员
				int n = flow.getVcSequence();
				if (n > 1) {// 第二个节点
					hql += " and (t.vcSequence='" + n + "' or t.vcSequence='"
							+ (n - 1) + "')";
				} else {
					hql += " and t.vcSequence='" + n + "'";
				}
			}

		} else if ("3".equals(user.getRootOrgLevel())) {
			hql += " and t.vcZgswj='2'";// 征管局可看。
		}
		hql += " order by t.dtDate";
		List<CaseSourceFiles> files = new ArrayList<CaseSourceFiles>();
		try {
			files = (List<CaseSourceFiles>) this.baselogic.searchByHql(hql);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		JSONArray jsonTree = new JSONArray();
		List<JsonTreeNode> fileList = new ArrayList<JsonTreeNode>();
		JsonTreeNode rootNode = new JsonTreeNode();
		rootNode.setId("1");
		rootNode.setIconCls("ext-icon-book_open");
		rootNode.setText("案源文书");
		rootNode.setState("open");
		if (files != null && files.size() > 0) {
			for (CaseSourceFiles file : files) {
				JsonTreeNode child = new JsonTreeNode();
				child.setId(file.getVcFileId());
				child.setText(file.getVcFileName());
				child.setIconCls("ext-icon-book_open");
				fileList.add(child);
			}
			rootNode.setChildren(fileList);
		}
		List<JsonTreeNode> nodeList = new ArrayList<JsonTreeNode>();
		nodeList.add(rootNode);
		jsonTree.add(nodeList); // 写入树节点信息
		// 以字符串为文件流进行输出
		// 由于形成的json格式与easyui的格式在外部多了个[]，因此在这里进行移除。
		writeHTML(jsonTree.toString()
				.substring(1, jsonTree.toString().length() - 1).toString()); // 将树以JSON格式的字符串进行输出

	}

	public String caseSourceHandOver() {
		String chkSelf = this.getParameter("chkSelf");
		WorkflowFlow flow = FlowWorkUtil.getWorkflowFlowByPerson(chkSelf,
				User.getUserId());
		if (flow != null && "2".equals(flow.getVcStatus())) {
			return this.writeHTML("不能重复移交！");
		} else {
			String vcParId = User.getParOrgIdByOrgLevel("2");
			List<SysVOrg> deps = OrgUtil.getChildDep(vcParId);

			StringBuffer op = new StringBuffer();
			if (deps != null && deps.size() > 0) {
				for (SysVOrg org : deps) {
					op.append("<option value='" + org.getVcId() + "'>"
							+ org.getVcName() + "</option>");
				}

			} else {
				op.append("<option value=''></option>");
			}
			this.setAttribute("deps", deps);
			return "caseSourceHandOver";
		}

	}

	public String handOverSuccessed() {
		String chkSelf = this.getParameter("chkSelf");
		String[] userids = this.getParameterValues("userIds[]");
		String[] username = this.getParameterValues("idnames[]");
		String vcOrgId = this.getParameter("vcOrgId");
		String vcType = this.getParameter("vcType");
		String vcAdvance = this.getParameter("vcAdvance");
		SysVOrg org = OrgUtil.getOrg(vcOrgId);
		CaseSource po = null;
		try {
			po = (CaseSource) this.baselogic.getPOByPk(
					CaseSource.class.getName(), chkSelf);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		FlowWorkUtil.transferFlowWork(chkSelf, vcType, User.getUserId(), "",
				"", vcOrgId, org.getVcName(), userids[0], username[0],
				vcAdvance);
		return this.returnInfoForJS(true, null);
	}

	/**
	 * 案源签收，置状态为处理中1
	 * 
	 * @return
	 */
	public String caseSourceReceiveSuccess() {
		String chkSelf = this.getParameter("chkSelf");
		WorkflowFlow flow = FlowWorkUtil.getWorkflowFlowStatuIs0ByPerson(
				chkSelf, User.getUserId());
		SysVOrg org = OrgUtil.getOrg(User.getUserOrgId());
		User user = User.getUser();
		if (flow != null
				&& ("0".equals(flow.getVcStatus()) || "3".equals(flow
						.getVcStatus()))) {
			if ("0".equals(flow.getVcStatus())) {// 第一次签收
				List<CaseSourceFilesTemplate> l = FlowWorkUtil
						.getWorkflowTemplateFiles("" + flow.getVcSequence(),
								"1");// 重要的文书
				String fileIds[] = null;
				if (l != null && l.size() > 0) {
					fileIds = new String[l.size()];
					for (int i = 0; i < l.size(); i++) {
						fileIds[i] = l.get(i).getVcFileId();
					}
				}

				if (fileIds != null) {
					List<PubFileUploadLog> l_ = NetFileUtil
							.getPubFileUploadLogs(fileIds);
					for (int i = 0; i < l_.size(); i++) {
						PubFileUploadLog log = new PubFileUploadLog();
						CaseSourceFiles files = new CaseSourceFiles();
						String fileName = l_.get(i).getVcFilename();
						int m = fileName.lastIndexOf(".");
						String fileType = fileName.substring(m,
								fileName.length());
						String sourceFilePath = FrameworkContext.getAppPath()
								+ l_.get(i).getVcChildFolder()
								+ l_.get(i).getVcId() + fileType;
						String yyyyMMddpath = DateUtil.format(new Date(),
								"yyyy")
								+ "/"
								+ DateUtil.format(new Date(), "MM")
								+ "/"
								+ DateUtil.format(new Date(), "dd");
						String fileId = GeneratorUUID.generateUUID();
						String dicPath = FrameworkContext.getAppPath()
								+ "approve/" + yyyyMMddpath + "/" + fileId
								+ fileType;
						File saveFile = new File(FrameworkContext.getAppPath()
								+ "approve/" + yyyyMMddpath + "/");
						if (!saveFile.exists())
							saveFile.mkdirs();
						files.setVcId(GeneratorUUID.generateUUID());
						files.setDtDate(new Date());
						files.setVcBrowse(l.get(i).getVcBrowse());
						files.setVcSequence(l.get(i).getVcSequence());
						files.setVcTemplateId(l.get(i).getVcId());
						files.setVcFileId(fileId);
						files.setVcFileName(fileName);
						files.setVcFlowId(flow.getVcId());
						files.setVcRecordId(chkSelf);
						files.setVcZgswj(l.get(i).getVcZgswj());
						files.setVcOrgId(User.getUserOrgId());
						files.setVcOrgName(org.getVcName());
						files.setVcPersonId(User.getUserId());
						files.setVcPersonName(User.getUserName());
						files.setVcJcjId(user.getRootOrgId());
						files.setVcJdjName(OrgUtil.getOrg(user.getRootOrgId())
								.getVcName());
						files.setVcDelFlag("0");

						log.setVcFilename(fileName);
						log.setVcId(fileId);
						log.setVcChildFolder("approve/" + yyyyMMddpath + "/");
						log.setVcDelFlag(0);

						DbUtil.addPo(log);
						DbUtil.addPo(files);
						FileUtil.copyFile(sourceFilePath, dicPath);
					}
				}
			}

			FlowWorkUtil
					.setReceiveFlag(chkSelf, User.getUserOrgId(),
							User.getUserOrgName(), User.getUserId(),
							User.getUserName());
		} else {
			return this.returnInfoForJS(false, "该案源已经签收，不能重复操作！");
		}
		return this.returnInfoForJS(true, "签收成功！");
	}

	public String ajaxPersons() {
		String vcOrgId = this.getParameter("vcOrgId");
		List<SysPerson> persons = OrgUtil.getUserByOrgId(vcOrgId, true);
		this.rows = persons;
		return JSON;
	}

	public String ajaxOrgs() {
		String vcOrgId = this.getParameter("vcOrgId");
		List<SysVOrg> orgs = OrgUtil.getChildDep(vcOrgId);
		this.rows = orgs;
		return JSON;
	}

	/**
	 * 案源退回界面
	 * 
	 * @return
	 */
	public String caseSourceGoBack() {
		return "caseSourceGoBack";
	}

	/**
	 * 案源退回操作
	 * 
	 * @return
	 */
	public String caseSourceGoBackSuccess() {
		String vcId = this.getParameter("chkSelf");
		String vcAdvance = this.getParameter("vcAdvance");

		String chkSelf = this.getParameter("chkSelf");
		WorkflowFlow flow = FlowWorkUtil.getWorkflowFlowByPerson(chkSelf,
				User.getUserId());
		if (flow != null
				&& ("0".equals(flow.getVcStatus()) || "1".equals(flow
						.getVcStatus()))) {
			if (1 == flow.getVcSequence().intValue()) {
				return this.returnInfoForJS(false, "回退失败！案源不允许回退至市局。");
			}
			/*
			 * 2015-04-27 by 刘渝洪，开始 修改代码：修改流程操作记录时的规范用词，移除“退回：” 原代码：
			 * FlowWorkUtil.backFlowWork(vcId,
			 * User.getUserOrgId(),User.getUserOrgName(), User.getUserId(),
			 * User.getUserName(),"退回："+vcAdvance); 修改为如下：
			 */
			FlowWorkUtil.backFlowWork(vcId, User.getUserOrgId(),
					User.getUserOrgName(), User.getUserId(),
					User.getUserName(), vcAdvance);
			/* 2015-04-27 by 刘渝洪，结束 */
		} else {
			if (flow == null) {
				return this.returnInfoForJS(false, "回退失败！案源不允许重复回退。");
			}
			if (1 == flow.getVcSequence().intValue()) {
				return this.returnInfoForJS(false, "回退失败！案源不允许回退至市局。");
			}
			// return this.alertMsg("该案源已经签收，不能重复操作！");
			return this.returnInfoForJS(false,
					"回退失败！只有未签收或者已签收未向下一环节移交的案源才能回退。");
		}

		return this.returnInfoForJS(true, "回退成功！");
	}

/**
 *
* @对应  caseSourceReceiveColumn4.jsp------案件进展情况统计
* */
	public String caseSourceReceiveColumn()
	{
		/*
		 * 2015-06-10 by 刘渝洪，开始 添加代码，添加各局的“转接案源”数据查询，为本年度之前已登记还未结案的案源数
		 * 若未查询到本年度的“转接案源”数据，则采集“转接案源”数据，并添加到转接案源表（CASE_SOURCE_YEAR$NOTEND）
		 */
		final int[] counts = new int[6];
		String curYear = DateUtil.getYear();
		int lastYear = Integer.valueOf(curYear) - 1;/*得到今年以前的年份=2015-1*/

		String sqlCount = "select count(year) as cnt from case_source_year$notend where year=" + lastYear;//查询-转接案源数
		DbUtil.executeSqlQuery(sqlCount, new ISQLMapper() {
															@Override
															public Object fromSQLQuery(ResultSet rs, int num)
															{
																TreeNode node = new TreeNode();
																try {
																	counts[0] = rs.getInt("cnt");
																} catch (SQLException e) {
																	// TODO Auto-generated catch block
																	e.printStackTrace();
																}
																return node;
															}
														}
		);//查询-转接案源数
		/****************************************************************************************************************************************/
		if (counts[0] > 0)
		{
			String sqlCounts = "select count_1,count_2,count_3,count_4,count_5 from case_source_year$notend where year=" + lastYear;
			DbUtil.executeSqlQuery(sqlCounts, new ISQLMapper() {
																	@Override
																	public Object fromSQLQuery(ResultSet rs, int num)
																	{
																		TreeNode node = new TreeNode();
																		try {
																			counts[1] = rs.getInt("count_1");
																			counts[2] = rs.getInt("count_2");
																			counts[3] = rs.getInt("count_3");
																			counts[4] = rs.getInt("count_4");
																			counts[5] = rs.getInt("count_5");
																		} catch (SQLException e) {
																			// TODO Auto-generated catch block
																			e.printStackTrace();
																		}
																		return node;
																	}
																}
			);
			
		}
		else
		{
			String sqlBase = "select count(*) as cnt from case_source t,t_workflow_work w where t.vc_id=w.vc_record_id AND t.vc_del$flag='0' AND w.vc_status<>'9' AND register_date<=to_date('" + curYear + "-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss')";
			// 第一稽查局15007010000
			String sqlCount1 = sqlBase + " AND t.INSPECTION_DEPT_ID='15007010000'";
			// 第二稽查局15007020000
			String sqlCount2 = sqlBase + " AND t.INSPECTION_DEPT_ID='15007020000'";
			// 第三稽查局15007030000
			String sqlCount3 = sqlBase + " AND t.INSPECTION_DEPT_ID='15007030000'";
			// 第四稽查局15007040000
			String sqlCount4 = sqlBase + " AND t.INSPECTION_DEPT_ID='15007040000'";
			// 第五稽查局15007050000
			String sqlCount5 = sqlBase + " AND t.INSPECTION_DEPT_ID='15007050000'";

			DbUtil.executeSqlQuery(sqlCount1, new ISQLMapper() {
																@Override
																public Object fromSQLQuery(ResultSet rs, int num)
																{
																	TreeNode node = new TreeNode();
																	try {
																		counts[1] = rs.getInt("cnt");
																	} catch (SQLException e) {
																		// TODO Auto-generated catch block
																		e.printStackTrace();
																	}
																	return node;
																}
															}
			);

			DbUtil.executeSqlQuery(sqlCount2, new ISQLMapper() {
																@Override
																public Object fromSQLQuery(ResultSet rs, int num)
																{
																	TreeNode node = new TreeNode();
																	try {
																		counts[2] = rs.getInt("cnt");
																	} catch (SQLException e) {
																		// TODO Auto-generated catch block
																		e.printStackTrace();
																	}
																	return node;
																}
															}
			);

			DbUtil.executeSqlQuery(sqlCount3, new ISQLMapper() {
																@Override
																public Object fromSQLQuery(ResultSet rs, int num)
																{
																	TreeNode node = new TreeNode();
																	try {
																		counts[3] = rs.getInt("cnt");
																	} catch (SQLException e) {
																		// TODO Auto-generated catch block
																		e.printStackTrace();
																	}
																	return node;
																}
															}
			);

			DbUtil.executeSqlQuery(sqlCount4, new ISQLMapper() {
																	@Override
																	public Object fromSQLQuery(ResultSet rs, int num)
																	{
																		TreeNode node = new TreeNode();
																		try {
																			counts[4] = rs.getInt("cnt");
																		} catch (SQLException e) {
																			// TODO Auto-generated catch block
																			e.printStackTrace();
																		}
																		return node;
																	}
																}
			);

			DbUtil.executeSqlQuery(sqlCount5, new ISQLMapper() {
																	@Override
																	public Object fromSQLQuery(ResultSet rs, int num)
																	{
																		TreeNode node = new TreeNode();
																		try {
																			counts[5] = rs.getInt("cnt");
																		} catch (SQLException e) {
																			// TODO Auto-generated catch block
																			e.printStackTrace();
																		}
																		return node;
																	}
																}
			);

			CaseSourceYearNotEnd 	caseNotEnd = new CaseSourceYearNotEnd();
									caseNotEnd.setYear(lastYear);
									caseNotEnd.setCount1(counts[1]);
									caseNotEnd.setCount2(counts[2]);
									caseNotEnd.setCount3(counts[3]);
									caseNotEnd.setCount4(counts[4]);
									caseNotEnd.setCount5(counts[5]);
									DbUtil.addPo(caseNotEnd);
		}
		/* 2015-06-10 by 刘渝洪，结束 */

		/* 2015-06-11 by 刘渝洪，开始 
		 * 修改代码：默认搜索范围：登记日期为本年的案源，如年初应为0
		 * 原代码：// 第一稽查局15007010000
		 * String sql = "select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9')  and (t.VC_REVOCATION is null or t.VC_REVOCATION=0 or t.VC_REVOCATION=1 or t.VC_REVOCATION=-1) and t.INSPECTION_DEPT_ID='15007010000' group by w.vc_status order by w.vc_status";
		 * 修改后代码：
		 */
		// 第一稽查局15007010000
		String sql = "select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9')  and (t.VC_REVOCATION is null or t.VC_REVOCATION=0 or t.VC_REVOCATION=1 or t.VC_REVOCATION=-1) and t.INSPECTION_DEPT_ID='15007010000' and register_date>=to_date('" + curYear + "-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss') and register_date<=to_date('" + curYear + "-12-31 23:59:59','yyyy-mm-dd hh24:mi:ss') group by w.vc_status order by w.vc_status";
		/* 2015-06-11 by 刘渝洪，结束 */

		// List<String> first=DbUtil.executeStringSqlQuery(sql);
		final Map<String, Integer> first_ = new HashMap<String, Integer>();
		DbUtil.executeSqlQuery(sql, new ISQLMapper() {

			@Override
			public Object fromSQLQuery(ResultSet rs, int num) {
				TreeNode node = new TreeNode();
				try {
					first_.put(rs.getString("vc_status"), rs.getInt("cnt"));
					first_.put("not_end", counts[1]);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				return node;
			}

		});

		this.setAttribute("first", first_);

		/* 2015-06-11 by 刘渝洪，开始 
		 * 修改代码：默认搜索范围：登记日期为本年的案源，如年初应为0
		 * 原代码：// 第二稽查局15007020000
		 * String sql = "select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9')  and (t.VC_REVOCATION is null or t.VC_REVOCATION=0 or t.VC_REVOCATION=1 or t.VC_REVOCATION=-1) and t.INSPECTION_DEPT_ID='15007020000' group by w.vc_status order by w.vc_status";
		 * 修改后代码：
		 */
		// 第二稽查局15007020000
		sql = "select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9') and (t.VC_REVOCATION is null or t.VC_REVOCATION=0 or t.VC_REVOCATION=1 or t.VC_REVOCATION=-1) and t.INSPECTION_DEPT_ID='15007020000' and register_date>=to_date('" + curYear + "-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss') and register_date<=to_date('" + curYear + "-12-31 23:59:59','yyyy-mm-dd hh24:mi:ss') group by w.vc_status order by w.vc_status";
		/* 2015-06-11 by 刘渝洪，结束 */

		final Map<String, Integer> second_ = new HashMap<String, Integer>();
		List<TreeNode> second = DbUtil.executeSqlQuery(sql, new ISQLMapper() {

			@Override
			public Object fromSQLQuery(ResultSet rs, int num) {
				TreeNode node = new TreeNode();
				try {
					second_.put(rs.getString("vc_status"), rs.getInt("cnt"));
					second_.put("not_end", counts[2]);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return node;
			}

		});
		this.setAttribute("second", second_);

		/* 2015-06-11 by 刘渝洪，开始 
		 * 修改代码：默认搜索范围：登记日期为本年的案源，如年初应为0
		 * 原代码：// 第三稽查局15007030000
		 * String sql = "select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9')  and (t.VC_REVOCATION is null or t.VC_REVOCATION=0 or t.VC_REVOCATION=1 or t.VC_REVOCATION=-1) and t.INSPECTION_DEPT_ID='15007030000' group by w.vc_status order by w.vc_status";
		 * 修改后代码：
		 */
		// 第三稽查局15007030000
		sql = "select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9')  and (t.VC_REVOCATION is null or t.VC_REVOCATION=0 or t.VC_REVOCATION=1 or t.VC_REVOCATION=-1) and t.INSPECTION_DEPT_ID='15007030000' and register_date>=to_date('" + curYear + "-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss') and register_date<=to_date('" + curYear + "-12-31 23:59:59','yyyy-mm-dd hh24:mi:ss') group by w.vc_status order by w.vc_status";
		/* 2015-06-11 by 刘渝洪，结束 */

		final Map<String, Integer> three_ = new HashMap<String, Integer>();
		List<TreeNode> three = DbUtil.executeSqlQuery(sql, new ISQLMapper() {

			@Override
			public Object fromSQLQuery(ResultSet rs, int num) {
				TreeNode node = new TreeNode();
				try {
					three_.put(rs.getString("vc_status"), rs.getInt("cnt"));
					three_.put("not_end", counts[3]);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return node;
			}

		});
		this.setAttribute("three", three_);

		/* 2015-06-11 by 刘渝洪，开始 
		 * 修改代码：默认搜索范围：登记日期为本年的案源，如年初应为0
		 * 原代码：// 第四稽查局15007040000
		 * String sql = "select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9')  and (t.VC_REVOCATION is null or t.VC_REVOCATION=0 or t.VC_REVOCATION=1 or t.VC_REVOCATION=-1) and t.INSPECTION_DEPT_ID='15007040000' group by w.vc_status order by w.vc_status";
		 * 修改后代码：
		 */
		// 第四稽查局15007040000
		sql = "select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9')  and (t.VC_REVOCATION is null or t.VC_REVOCATION=0 or t.VC_REVOCATION=1 or t.VC_REVOCATION=-1) and t.INSPECTION_DEPT_ID='15007040000' and register_date>=to_date('" + curYear + "-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss') and register_date<=to_date('" + curYear + "-12-31 23:59:59','yyyy-mm-dd hh24:mi:ss') group by w.vc_status order by w.vc_status";
		/* 2015-06-11 by 刘渝洪，结束 */

		final Map<String, Integer> four_ = new HashMap<String, Integer>();
		List<TreeNode> four = DbUtil.executeSqlQuery(sql, new ISQLMapper() {

			@Override
			public Object fromSQLQuery(ResultSet rs, int num) {
				TreeNode node = new TreeNode();
				try {
					four_.put(rs.getString("vc_status"), rs.getInt("cnt"));
					four_.put("not_end", counts[4]);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return node;
			}

		});
		this.setAttribute("four", four_);
/**************************************************第五稽查局15007050000**************************************************/
		/* 2015-06-11 by 刘渝洪，开始 
		 * 修改代码：默认搜索范围：登记日期为本年的案源，如年初应为0
		 * 原代码：// 第五稽查局15007050000
		 * String sql = "select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9')  and (t.VC_REVOCATION is null or t.VC_REVOCATION=0 or t.VC_REVOCATION=1 or t.VC_REVOCATION=-1) and t.INSPECTION_DEPT_ID='15007050000' group by w.vc_status order by w.vc_status";
		 * 修改后代码：
		 */
		sql = "select count(*) as cnt,w.vc_status from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','-2','2','3','4','9')  and (t.VC_REVOCATION is null or t.VC_REVOCATION=0 or t.VC_REVOCATION=1 or t.VC_REVOCATION=-1) and t.INSPECTION_DEPT_ID='15007050000' and register_date>=to_date('" + curYear + "-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss') and register_date<=to_date('" + curYear + "-12-31 23:59:59','yyyy-mm-dd hh24:mi:ss') group by w.vc_status order by w.vc_status";
		/* 2015-06-11 by 刘渝洪，结束 */

		final Map<String, Integer> five_ = new HashMap<String, Integer>();
		List<TreeNode> five = DbUtil.executeSqlQuery(sql, new ISQLMapper() {
																			@Override
																			public Object fromSQLQuery(ResultSet rs, int num) {
																				TreeNode node = new TreeNode();
																				try {
																					five_.put(rs.getString("vc_status"), rs.getInt("cnt"));
																					five_.put("not_end", counts[5]);
																				} catch (SQLException e) {
																					// TODO Auto-generated catch block
																					e.printStackTrace();
																				}
																				return node;
																			}

																		});
		this.setAttribute("five", five_);

		// List<String> first=new ArrayList<String>();
		// first.add("2");first.add("8");first.add("20");first.add("5");first.add("7");
		// this.setAttribute("first", first.toString());
		//
		// List<String> second=new ArrayList<String>();
		// second.add("3");second.add("5");second.add("10");second.add("3");second.add("2");
		// this.setAttribute("second", second.toString());
		//
		// List<String> three=new ArrayList<String>();
		// three.add("6");three.add("5");three.add("4");three.add("8");three.add("4");
		// this.setAttribute("three", three.toString());
		//
		// List<String> four=new ArrayList<String>();
		// four.add("8");four.add("3");four.add("11");four.add("4");four.add("5");
		// this.setAttribute("four", four.toString());
		//
		// List<String> five=new ArrayList<String>();
		// five.add("6");five.add("7");five.add("12");five.add("7");five.add("8");
		// this.setAttribute("five", five.toString());
		// return "caseSourceReceiveColumn";
		return "caseSourceReceiveColumn";
	}

	public String caseSourceReceiveColumn2() {
		String sql = "select count(*) as cnt from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','2','3','4','9')  group by t.INSPECTION_DEPT_ID order by t.INSPECTION_DEPT_ID";//
		List<String> first = DbUtil.executeStringSqlQuery(sql);
		this.setAttribute("first", first.toString());

		// List<String> first=new ArrayList<String>();
		// first.add("8");first.add("5");first.add("10");first.add("3");first.add("6");
		// this.setAttribute("first", first.toString());
		return "caseSourceReceiveColumn2";
	}

	public String caseSourceReceiveColumn3() {
		String sql = "select count(*) as cnt from CASE_SOURCE t,T_WORKFLOW_WORK w where t.vc_id=w.VC_RECORD_ID and t.vc_del$flag='0' and w.vc_status in('1','2','3','4','9')  group by w.vc_status";//
		List<String> first = DbUtil.executeStringSqlQuery(sql);
		this.setAttribute("first", first.toString());

		// List<String> first=new ArrayList<String>();
		// first.add("8");first.add("5");first.add("10");first.add("3");
		// this.setAttribute("first", first.toString());
		return "caseSourceReceiveColumn3";
	}

	public String getCaseSourceDb() {
		return "getCaseSourceDb";
	}




	public String getCaseSourceDbJs() {
		User user = User.getUser();
		List<CaseSource> list = FlowWorkUtil.getCaseSourceDb(user.getUserOrgId(), user.getUserId());
		this.rows = list;
		return JSON;
	}

	/**
	 * 案源合并窗口
	 * 
	 * @return
	 */
	public String openJoinPage() {

		String vcId = this.getParameter("chkSelf");
		this.setAttribute("vcId", vcId);

		/* 2015-06-11 by 刘渝洪，开始 
		 * 添加代码：开启合并案源弹窗后，显示可合并案源（立案的案源）的列表
		 * 主案源条件：已立案下达，未结案，非合并状态
		 */
		CaseSource po = null;
		try {
			po = (CaseSource) this.baselogic.getPOByPk(CaseSource.class.getName(), vcId);
		} catch (AppException e) {
			e.printStackTrace();
		}

		String sql = "from CaseSource where vcId<>'"+vcId+"' and caseNumber is not null and endDate is null and (vcJoin='0' or vcJoin is null) and (taxpayerNumber='" + po.getTaxpayerNumber() + "' or involvedEnterprice='" + po.getInvolvedEnterprice() + "')";

		List list = DbUtil.executeHql(sql);
		this.setAttribute("list", list);
		/* 2015-06-11 by 刘渝洪，结束 */

		return "openJoinPage";
	}

	/**
	 * 合并案源时，主案源查询
	 * 
	 * @return
	 */
	public String ajaxJoinMainCaseSources() {
		String vcId = this.getParameter("chkSelf");
		String nsrsbh = this.getParameter("nsrsbh");
		String nsrmc = this.getParameter("nsrmc");

		String sql = "from CaseSource where vcId<>'"+vcId+"' and caseNumber is not null and endDate is null and (vcJoin='0' or vcJoin is null)";

		if(nsrsbh != null && nsrsbh.trim().length() > 0 && nsrmc != null && nsrmc.trim().length() > 0){
			sql = sql + " and (taxpayerNumber='" + nsrsbh + "' and involvedEnterprice like '%" + nsrmc + "%')";
		}
		if(nsrsbh != null && nsrsbh.trim().length() > 0 && (nsrmc == null || nsrmc.trim().length()==0)) {
			sql = sql + " and taxpayerNumber='" + nsrsbh + "'";
		}
		if((nsrsbh == null || nsrsbh.trim().length() == 0) && (nsrmc != null && nsrmc.trim().length() > 0)) {
			sql = sql + " and involvedEnterprice like '%" + nsrmc + "%')";
		}

		List list = DbUtil.executeHql(sql);

		this.rows = list;
		return JSON;
	}

	/**
	 * 合并提交
	 * 
	 * @return
	 */
	public String caseSourceJoinSuccess() {
		String vcAdvance = this.getParameter("vcAdvance");
		String chkSelf = this.getParameter("chkSelf");

		/* 2015-06-11 by 刘渝洪，开始 
		 * 添加代码，对合并案源，增加选取多个合并案源，并且选取主案源的合并处理
		 */
		String nsrsbh = this.getParameter("txtNsrsbh");
		String nsrmc = this.getParameter("txtNsrmc");
		String vcIdJoinTo = this.getParameter("chkJoinMainCaseSource");

		CaseSource poJoinTo = null;
		boolean isSelectMain = false;
		boolean isJoinInput = false;

		// 根据页面是否选取主案源，决定当前案源是否合并到主案源
		if(vcIdJoinTo != null && vcIdJoinTo.length() > 0) {
			isSelectMain = true;

			// 根据页面选择【系统设置】还是【手动输入】，决定当前案源合并时【纳税人识别号】和【纳税人名称】的设值，默认为【系统设置】
			if (nsrsbh != null && nsrsbh.length() > 0) {
				// 用户选择【手动输入】，更新为手动输入值
				isJoinInput = true;
			}

			// 用户选择【系统设置】，则取得选定的主案源数据
			// 将当前案源【纳税人识别号】设置为主案源【案源编号】，将当前案源【纳税人名称】设置为主案源【纳税人名称】
			try {
				poJoinTo = (CaseSource) this.baselogic.getPOByPk(
						CaseSource.class.getName(), vcIdJoinTo);
			} catch (AppException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		/* 2015-06-11 by 刘渝洪，结束 */

		CaseSource po = null;
		try {
			po = (CaseSource) this.baselogic.getPOByPk(
					CaseSource.class.getName(), chkSelf);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		po.setVcJoin("1");// 一合并
		po.setVcJoinman(User.getUserName());
		po.setVcJoinmanId(User.getUserId());

		/* 2015-06-11 by 刘渝洪，开始 
		 * 添加代码，根据用户页面选择，决定当前案源的【纳税人识别号】与【纳税人名称】的值
		 */
		if(isSelectMain){
			if(isJoinInput){
				po.setTaxpayerNumber(nsrsbh);
				po.setInvolvedEnterprice(nsrmc);
				poJoinTo.setTaxpayerNumber(nsrsbh);
				poJoinTo.setInvolvedEnterprice(nsrmc);
			} else {
				po.setTaxpayerNumber(poJoinTo.getCaseNumber());
				po.setInvolvedEnterprice(poJoinTo.getInvolvedEnterprice());
				poJoinTo.setTaxpayerNumber(poJoinTo.getCaseNumber());
			}
		}
		/* 2015-06-11 by 刘渝洪，结束 */

		try {
			this.baselogic.updatePo(po);
			this.baselogic.updatePo(poJoinTo);
		} catch (AppException e) {
			e.printStackTrace();
		}
		FlowWorkUtil.saveWorkflowMan(chkSelf, vcAdvance);

		return this.returnInfoForJS(true, "合并成功！");
	}

	/**
	 * 案源撤销操作 跨区局选案岗进行操作
	 * 
	 * @return
	 */
	public String caseSourceRevocation() {
		String vcId = this.getParameter("chkSelf");
		this.setAttribute("vcId", vcId);//

		return "openRevocationPage";
	}

	/**
	 * 撤销提请成功
	 * 
	 * @return
	 */
	public String caseSourceRevocationSuccess() {
		String vcAdvance = this.getParameter("vcAdvance");
		String chkSelf = this.getParameter("chkSelf");

		CaseSource po = null;
		try {
			po = (CaseSource) this.baselogic.getPOByPk(
					CaseSource.class.getName(), chkSelf);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		po.setVcRevocation("1");
		try {
			this.baselogic.updatePo(po);
		} catch (AppException e) {
			e.printStackTrace();
		}
		FlowWorkUtil.saveWorkflowMan(chkSelf, vcAdvance);

		return this.returnInfoForJS(true, "案源撤销申请已提交，请及时报送纸质审批表！");
	}

	// 打开撤销审批界面
	public String openShRevocationPage() {
		User user = User.getUser();
		String vcId = this.getParameter("chkSelf");

		this.setAttribute("vcId", vcId);//
		return "openShRevocationPage";
	}

	/**
	 * 案源撤销操作 跨区局选案岗进行操作
	 * 
	 * @return
	 */
	public String caseSourceShRevocationSuccess() {
		String vcAdvance = this.getParameter("vcAdvance");
		String shFlag = this.getParameter("shFlag");
		String chkSelf = this.getParameter("vcId");
		CaseSource po = null;
		try {
			po = (CaseSource) this.baselogic.getPOByPk(
					CaseSource.class.getName(), chkSelf);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		po.setVcRevocation(shFlag);
		try {
			this.baselogic.updatePo(po);
		} catch (AppException e) {
			e.printStackTrace();
		}
		FlowWorkUtil.saveWorkflowMan(chkSelf, vcAdvance);

		return this.returnInfoForJS(true, "撤销成功！");
	}

	public String caseSourceFlowPage() {
		String vcRecordId = this.getParameter("chkSelf");
		List<FlowPicView> list = new ArrayList<FlowPicView>();
		List<WorkflowFlow> flows = FlowWorkUtil.getWorkflowFlows(vcRecordId);

		WorkflowFlow o = null;
		String statu = "";
		if (flows != null && flows.size() > 0) {
			for (int i = 1; i <= flows.size(); i++) {
				o = flows.get(i - 1);
				statu = o.getVcStatus();
				list.add(new FlowPicView(getNodeName(i), "处理人："
						+ flows.get(i - 1).getVcHandlePersonName(), "2"
						.equals(statu) ? "comp" : "1".equals(statu) ? "ing"
						: "unf"));
			}
			for (int i = flows.size() + 1; i <= 4; i++) {
				list.add(new FlowPicView(getNodeName(i), "", "unf"));
			}
		} else {
			for (int i = 1; i <= 4; i++) {
				list.add(new FlowPicView(getNodeName(i), "", "unf"));
			}
		}

		JSONArray ary = new JSONArray();
		ary.addAll(list);
		setAttribute("flowpic", ary.toString());
		List<WorkflowMan> mans = FlowWorkUtil
				.getWorkflowMansByRecordId(vcRecordId);
		setAttribute("flows", mans);
		return "caseSourceFlowPage";
	}

	private String getNodeName(int i) {
		String info = "";
		if (i == 1)
			info = "选案";
		else if (i == 2)
			info = "检查";
		else if (i == 3)
			info = "审理";
		else if (i == 4)
			info = "执行";
		return info;
	}

	/**
	 * 打开案源下发界面
	 * 
	 * @return
	 * @throws AppException
	 */
	public String caseSourceDown() throws AppException {
		String vcId = this.getParameter("chkSelf");

		String ids[] = this.getParameterValues("chkSelf");

		if (ids != null && ids.length > 0) {
			String idssql = StringUtil.fromArrayToStr(ids, true);
			String ids_str = StringUtil.fromArrayToStr(ids, false);
			String hql = "from CaseSource p where p.vcId in(" + idssql + ")";
			List<CaseSource> downpos = (List<CaseSource>) this.baselogic
					.searchByHql(hql);
			String inspectionDeptId = "";// 稽查局ID
			if (downpos != null && downpos.size() > 0) {
				inspectionDeptId = downpos.get(0).getInspectionDeptId();
			}
			boolean b = false;
			boolean state = false;// 是否存在已下发的案源
			for (CaseSource po : downpos) {
				if (!inspectionDeptId.equals(po.getInspectionDeptId())) {// 选择的案源有其他稽查局
					b = true;
					break;
				}
				if ("3".equals(po.getState())) {
					state = true;
					break;
				}
			}
			if (b) {
				return this.alertMsgAndExecJs("请检查所选择的的案源，确保属于同一稽查局！",
						"$('#operateWindow').window('close');");
			}
			if (state) {
				return this.alertMsgAndExecJs("所选择的案源有已经下发过的案源！请核实再下发",
						"$('#operateWindow').window('close');");
			}

			List<SysVOrg> deps = OrgUtil.getChildDep(inspectionDeptId);

			List<SysPerson> l = OrgUtil
					.getDefaultUserReceiveCaseByOrgId(inspectionDeptId);
			if (l != null && l.size() > 0) {
				this.setAttribute("default", l.get(0).getVcName());
			}

			StringBuffer op = new StringBuffer();
			if (deps != null && deps.size() > 0) {
				for (SysVOrg org : deps) {
					op.append("<option value='" + org.getVcId() + "'>"
							+ org.getVcName() + "</option>");
				}

			} else {
				op.append("<option value=''></option>");
			}
			this.setAttribute("deps", deps);
			this.setAttribute("vcId", ids_str);

			return "caseSourceDown";

		} else {
			return this.alertMsgAndExecJs("请选择要下发的案源！",
					"$('#operateWindow').window('close');");
		}

		/**
		 * WorkflowFlow flow=FlowWorkUtil.getWorkflowFlowByVcSeq(vcId, "1");
		 * if(flow!=null) { return this.alertMsgAndExecJs("该案源已经下发，不能重复操作！",
		 * "$('#operateWindow').window('close');"); } else{ CaseSource
		 * source=null; try { source=(CaseSource)this.baselogic.getPOByPk(
		 * "com.ce.cases.source.dao.po.CaseSource", vcId); } catch (AppException
		 * e) { // TODO Auto-generated catch block e.printStackTrace(); }
		 * 
		 * 
		 * List<SysVOrg> deps=OrgUtil.getChildDep(source.getInspectionDeptId());
		 * 
		 * List<SysPerson> l=
		 * OrgUtil.getDefaultUserReceiveCaseByOrgId(source.getInspectionDeptId
		 * ()); if(l!=null&&l.size()>0){ this.setAttribute("default",
		 * l.get(0).getVcName()); }
		 * 
		 * StringBuffer op = new StringBuffer(); if(deps!=null&&deps.size()>0){
		 * for(SysVOrg org:deps){
		 * op.append("<option value='"+org.getVcId()+"'>"+
		 * org.getVcName()+"</option>"); }
		 * 
		 * }else{ op.append("<option value=''></option>"); }
		 * this.setAttribute("deps", deps); this.setAttribute("vcId", vcId);
		 * 
		 * return "caseSourceDown";
		 * 
		 * 
		 * }
		 **/
		// String vcParId=User.getParOrgIdByOrgLevel("1");

	}

	//
	public String caseSourceDownSuccess() throws AppException {
		String vcRecordId = this.getParameter("chkSelf");

		String handOverId = this.getParameter("handOverId");
		String handOverName = this.getParameter("handOverName");
		String vcHandleOrgId = "", vcHandleOrgName = "", vcHandlePersonId = "", vcHandlePersonName = "";
		// String vcHandleOrgName=OrgUtil.getOrgName(vcHandleOrgId);
		// String vcHandlePersonId=this.getParameter("handOverPersonId");
		// String vcHandlePersonName=this.getParameter("handOverPerson");
		String vcDesc = this.getParameter("vcAdvance");
		/*
		 * 2015-04-24 by 刘渝洪，开始 移除代码：修改流程信息用词，由【下达：xxx】变为下拉菜单里三选一：
		 * 【阅处】，【立案查处】，【合并案源】 原代码： vcDesc="下达："+vcDesc; 2015-04-24 by 刘渝洪，结束
		 */
		String vcType = this.getParameter("vcType");

		String[] ids = vcRecordId.split(",");
		String sqlstr = StringUtil.fromArrayToStr(ids, true);

		if (ids != null && ids.length > 0) {
			String hql = "from CaseSource p where p.vcId in(" + sqlstr + ")";
			List<CaseSource> downpos = (List<CaseSource>) this.baselogic
					.searchByHql(hql);
			for (CaseSource source : downpos) {
				source.setState(3);
				SysVOrg jcjorg = OrgUtil.getOrg(source.getInspectionDeptId());
				String year = DateUtil.getYear();
				String sql = "select count(*) from CASE_SOURCE t where t.INSPECTION_DEPT_ID='"
						+ source.getInspectionDeptId()
						+ "' and t.STATE=3 and t.vc_del$flag='0'";
				int cnt = DbUtil.getFirstIntSqlQuery(sql);
				String cnt_ = "";
				if (cnt < 10)
					cnt_ = "00" + cnt;
				else if (cnt < 100)
					cnt_ = "0" + cnt;
				else
					cnt_ = "" + cnt;
				source.setCaseNumber(year + "-J" + jcjorg.getNseq() + "-"
						+ cnt_);
				source.setVcDownmanId(User.getUserId());
				source.setVcDownman(User.getUserName());
				try {
					this.baselogic.updatePo(source);
				} catch (AppException e) {
				}
				if ("1".equals(vcType)) {// 下发到人员
					if (StringUtil.isBlank(handOverId)) {
						List<SysPerson> l = OrgUtil
								.getDefaultUserReceiveCaseByOrgId(source
										.getInspectionDeptId());
						SysPerson person = null;
						if (l != null && l.size() > 0) {
							person = l.get(0);
						}
						if (person != null) {
							vcHandlePersonId = person.getVcId();
							vcHandlePersonName = person.getVcName();
						}
					} else {
						vcHandlePersonId = handOverId;
						vcHandlePersonName = handOverName;
					}

					vcHandleOrgId = OrgUtil.getOrgIdByUserId(vcHandlePersonId);
					vcHandleOrgName = OrgUtil
							.getOrgNameByUserId(vcHandlePersonId);
					FlowWorkUtil.setDownFlowWork(vcRecordId, vcType,
							User.getUserOrgId(), User.getUserOrgName(),
							User.getUserId(), User.getUserName(),
							vcHandleOrgId, vcHandleOrgName, vcHandlePersonId,
							vcHandlePersonName, vcDesc);
				} else {
					vcHandleOrgId = handOverId;
					vcHandleOrgName = handOverName;
					FlowWorkUtil.setDownFlowWork(vcRecordId, vcType,
							User.getUserOrgId(), User.getUserOrgName(),
							User.getUserId(), User.getUserName(),
							vcHandleOrgId, vcHandleOrgName, vcHandlePersonId,
							vcHandlePersonName, vcDesc);
				}
			}
		}

		/**
		 * CaseSource source=null; try { source = (CaseSource)
		 * this.baselogic.getPOByPk(CaseSource.class.getName(), vcRecordId); }
		 * catch (AppException e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); } source.setState(3); SysVOrg
		 * jcjorg=OrgUtil.getOrg(source.getInspectionDeptId()); String
		 * year=DateUtil.getYear(); String sql=
		 * "select count(*) from CASE_SOURCE t where t.INSPECTION_DEPT_ID='"
		 * +source
		 * .getInspectionDeptId()+"' and t.STATE=3 and t.vc_del$flag='0'"; int
		 * cnt=DbUtil.getFirstIntSqlQuery(sql); String cnt_=""; if(cnt<10)
		 * cnt_="00"+cnt; else if(cnt<100) cnt_="0"+cnt; else cnt_=""+cnt;
		 * source.setCaseNumber(year+"-J"+jcjorg.getNseq()+"-"+cnt_);
		 * source.setVcDownmanId(User.getUserId());
		 * source.setVcDownman(User.getUserName()); try {
		 * this.baselogic.updatePo(source); } catch (AppException e) { }
		 * if("1".equals(vcType)){//下发到人员 if(StringUtil.isBlank(handOverId)){
		 * List<SysPerson> l=
		 * OrgUtil.getDefaultUserReceiveCaseByOrgId(source.getInspectionDeptId
		 * ()); SysPerson person=null; if(l!=null&&l.size()>0){ person=l.get(0);
		 * } if(person!=null){ vcHandlePersonId=person.getVcId();
		 * vcHandlePersonName=person.getVcName(); } }else{
		 * vcHandlePersonId=handOverId; vcHandlePersonName=handOverName; }
		 * 
		 * 
		 * vcHandleOrgId=OrgUtil.getOrgIdByUserId(vcHandlePersonId);
		 * vcHandleOrgName=OrgUtil.getOrgNameByUserId(vcHandlePersonId);
		 * FlowWorkUtil
		 * .setDownFlowWork(vcRecordId,vcType,User.getUserOrgId(),User
		 * .getUserOrgName(),User.getUserId(),User.getUserName(), vcHandleOrgId,
		 * vcHandleOrgName, vcHandlePersonId, vcHandlePersonName, vcDesc);
		 * }else{ vcHandleOrgId=handOverId; vcHandleOrgName=handOverName;
		 * FlowWorkUtil
		 * .setDownFlowWork(vcRecordId,vcType,User.getUserOrgId(),User
		 * .getUserOrgName(),User.getUserId(),User.getUserName(), vcHandleOrgId,
		 * vcHandleOrgName, vcHandlePersonId, vcHandlePersonName, vcDesc); }
		 */
		return this.returnInfoForJS(true, null);
	}

	public String showCaseSourceFile() {
		String vcId = this.getParameter("chkSelf");
		String vcType = this.getParameter("vcType");
		String vcFileId = this.getParameter("vcFileId");
		String vcFileName = this.getParameter("fileName");
		String fileType = "";
		if (vcFileName.contains("."))
			fileType = vcFileName.substring(vcFileName.indexOf("."),
					vcFileName.length());
		this.setAttribute("fileType", fileType);
		this.setAttribute("vcFileName", vcFileName);
		String filePath = "";
		try {
			filePath = NetFileUtil.getFileServerPath(vcFileId);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		this.setAttribute("filePath", filePath);
		List<CaseSourceFiles> l = new ArrayList<CaseSourceFiles>();
		String hql = "from CaseSourceFiles p where p.vcFileId='" + vcFileId
				+ "' and p.vcDelFlag='0' ";
		try {
			l = (List<CaseSourceFiles>) this.baselogic.searchByHql(hql);
		} catch (AppException e) {
		}
		if (l != null && l.size() > 0) {
			if (l.get(0).getVcPersonId().equals(User.getUserId())) {
				this.setAttribute("readonly", "true");
			} else {
				this.setAttribute("readonly", "false");
			}
		} else {
			this.setAttribute("readonly", "false");
		}
		return "showCaseSourceFile";
	}

	// 上传文书
	public String checkNoticePage() {
		String vcId = this.getParameter("chkSelf");
		String fileType = this.getParameter("fileType");
		CaseSource casePo = null;
		try {
			casePo = (CaseSource) this.baselogic.getPOByPk(
					CaseSource.class.getName(), vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		WorkflowFlow flow = FlowWorkUtil.getCurOrgWorkflowFlow(vcId);
		if (flow != null) {
			this.setAttribute("vcSequence", flow.getVcSequence());
		}
		this.setAttribute("po", casePo);
		this.setAttribute("fileType", fileType);
		this.setAttribute("userName", User.getUserName());
		this.setAttribute("dtDate", DateUtil.format(new Date(), "yyyy年MM月dd日"));
		return "caseCheckNoticePage";
	}

	/*
	 * 上传文书
	 */
	public String addCheckNotice() throws AppException {
		String vcRecordId = this.getParameter("vcRecordId");
		String vcFileId = this.getParameter("fileId");
		WorkflowFlow flow = FlowWorkUtil.getCurOrgWorkflowFlow(vcRecordId);
		// String vcFileName=this.getParameter("fileName");
		// String fileIds[]=vcFileId.split(",");
		// String fileNames[]=vcFileName.split(",");
		// WorkflowFlow flow=FlowWorkUtil.getCurOrgWorkflowFlow(vcRecordId);
		// CaseSourceFiles file=new CaseSourceFiles();
		// for(int i=0;i<fileIds.length;i++){
		// file.setVcId(GeneratorUUID.generateUUID());
		// file.setDtDate(new Date());
		// file.setVcDelFlag("0");
		// file.setVcOrgId(User.getUserOrgId());
		// file.setVcOrgName(User.getUserOrgName());
		// file.setVcPersonId(User.getUserId());
		// file.setVcPersonName(User.getUserName());
		// file.setVcFileId(fileIds[i]);
		// file.setVcFileName(fileNames[i]);
		// file.setVcRecordId(vcRecordId);
		// if(flow!=null)
		// file.setVcFlowId(flow.getVcId());
		// baselogic.addPo(file);
		// FlowWorkUtil.saveWorkflowMan(vcRecordId,"上传"+fileNames[i]);
		// }

		// 第一次签收
		CaseSourceFilesTemplate fileTemplate = (CaseSourceFilesTemplate) this.baselogic
				.getPOByPk(CaseSourceFilesTemplate.class.getName(), vcFileId);

		if (fileTemplate != null) {
			SysVOrg org = OrgUtil.getOrg(User.getUserOrgId());
			User user = User.getUser();
			List<PubFileUploadLog> l_ = NetFileUtil
					.getPubFileUploadLogs(new String[] { fileTemplate
							.getVcFileId() });
			for (int i = 0; i < l_.size(); i++) {
				PubFileUploadLog log = new PubFileUploadLog();
				CaseSourceFiles files = new CaseSourceFiles();
				String fileName = l_.get(i).getVcFilename();
				int m = fileName.lastIndexOf(".");
				String fileType = fileName.substring(m, fileName.length());
				String sourceFilePath = FrameworkContext.getAppPath()
						+ l_.get(i).getVcChildFolder() + l_.get(i).getVcId()
						+ fileType;
				String yyyyMMddpath = DateUtil.format(new Date(), "yyyy") + "/"
						+ DateUtil.format(new Date(), "MM") + "/"
						+ DateUtil.format(new Date(), "dd");
				String fileId = GeneratorUUID.generateUUID();
				String dicPath = FrameworkContext.getAppPath() + "approve/"
						+ yyyyMMddpath + "/" + fileId + fileType;
				File saveFile = new File(FrameworkContext.getAppPath()
						+ "approve/" + yyyyMMddpath + "/");
				if (!saveFile.exists())
					saveFile.mkdirs();

				log.setVcFilename(fileName);
				log.setVcId(fileId);
				log.setVcChildFolder("approve/" + yyyyMMddpath + "/");
				log.setVcDelFlag(0);

				files.setVcId(GeneratorUUID.generateUUID());
				files.setDtDate(new Date());
				files.setVcBrowse(fileTemplate.getVcBrowse());
				files.setVcSequence(fileTemplate.getVcSequence());
				files.setVcTemplateId(fileTemplate.getVcId());
				files.setVcFileId(fileId);
				files.setVcFileName(fileTemplate.getVcFileName());
				if (flow != null)
					files.setVcFlowId(flow.getVcId());
				files.setVcRecordId(vcRecordId);
				files.setVcZgswj(fileTemplate.getVcZgswj());
				files.setVcOrgId(User.getUserOrgId());
				files.setVcOrgName(org.getVcName());
				files.setVcPersonId(User.getUserId());
				files.setVcPersonName(User.getUserName());
				files.setVcJcjId(user.getRootOrgId());
				files.setVcJdjName(OrgUtil.getOrg(user.getRootOrgId())
						.getVcName());
				files.setVcDelFlag("0");

				DbUtil.addPo(log);
				DbUtil.addPo(files);
				FileUtil.copyFile(sourceFilePath, dicPath);
				/*
				 * 2015-05-19 by 刘渝洪，开始 修改代码：移除“上传”，只记录文件名 原代码：
				 * FlowWorkUtil.saveWorkflowMan(vcRecordId,"上传"+fileName);
				 */
				FlowWorkUtil.saveWorkflowMan(vcRecordId, fileName);
				/* 2015-05-19 by 刘渝洪，结束 */
			}
		}

		return this.returnInfoForJS(true, "上传成功!");
	}

	/*
	 * 处理审批页面
	 */
	public String dealApprovePage() throws AppException {
		String caseId = this.getParameter("caseId");
		CaseSource source = (CaseSource) this.baselogic.getPOByPk(
				"com.ce.cases.source.dao.po.CaseSource", caseId);
		List approveList = this.baselogic
				.searchByHql("From CaseSourceApprove po where po.caseId='"
						+ caseId + "' and po.vcDelFlag=0");
		if (!approveList.isEmpty()) {
			appr = (CaseSourceApprove) approveList.get(0);
		} else {
			appr = new CaseSourceApprove();
			appr.setCaseId(source.getVcId());
			appr.setCaseFrom(source.getCaseFromName());
			appr.setCaseNum(source.getCaseNumber());
			appr.setInvolvedEnterprice(source.getInvolvedEnterprice());
			appr.setTaxpayerNumber(source.getTaxpayerNumber());
		}
		return "dealApprovePage";
	}

	/*
	 * 处理审批操作
	 */
	public String dealApprove() {
		try {
			// 修改审批表
			if (StringUtil.isNotBlank(appr.getVcId())) {
				appr.setVcDelFlag(0);
				this.baselogic.updatePo(appr);
			} else {// 添加审批表
				appr.setVcId(GeneratorUUID.generateUUID());
				appr.setVcDelFlag(0);
				this.baselogic.addPo(appr);
			}
		} catch (AppException e) {
			LogUtil.logError(e);
			return this.returnInfoForJS(false,
					e.getMessage().replaceAll("'|\\n", " "));
		}
		return this.returnInfoForJS(true, null);
	}

	/*
	 * 打开检查查看页面
	 */
	public String openCheckPage() throws AppException {
		String caseId = this.getParameter("chkSelf");
		String hql = " from CaseSourceCheck p where p.vcDelFlag='0' and p.caseId='"
				+ caseId + "'";
		List<CaseSourceCheck> l = (List<CaseSourceCheck>) this.baselogic
				.searchByHql(hql);

		if (l != null && l.size() > 0) {
			this.po = l.get(0);
		} else {

		}

		List<SysDictItem> itemList = DictUtil.getDictListByName("检查案源台账-采取措施");
		this.setAttribute("itemList", itemList);
		return "openCheckPage";
	}

	/*
	 * 打开执行查看页面
	 */
	public String openExceutePage() throws AppException {
		String caseId = this.getParameter("chkSelf");
		String hql = " from CaseSourceExecute p where p.vcDelFlag='0' and p.caseId='"
				+ caseId + "'";
		List<CaseSourceExecute> l = (List<CaseSourceExecute>) this.baselogic
				.searchByHql(hql);

		if (l != null && l.size() > 0) {
			this.po = l.get(0);
		} else {

		}

		return "openExceutePage";
	}

	/*
	 * 打开举报查看页面
	 */
	public String openReportPage() throws AppException {
		String caseId = this.getParameter("chkSelf");
		CaseSource source = (CaseSource) this.baselogic.getPOByPk(
				"com.ce.cases.source.dao.po.CaseSource", caseId);

		String hql = " from ReportTaxIllegal p where p.vcDelFlag='0' and p.vcId='"
				+ source.getReportId() + "'";
		List<CaseSourceExecute> l = (List<CaseSourceExecute>) this.baselogic
				.searchByHql(hql);
		// this.getUser()
		if (l != null && l.size() > 0) {
			this.po = l.get(0);
		} else {

		}

		return "openReportPage";
	}

	/*
	 * 打开纳税人查看页面
	 */
	public String openNsrPage() throws AppException {
		String caseId = this.getParameter("chkSelf");
		CaseSource source = (CaseSource) this.baselogic.getPOByPk(
				"com.ce.cases.source.dao.po.CaseSource", caseId);

		// String
		// sql="select t.* from EXPORT_TABLE t where t.NSRSBH='"+source.getTaxpayerNumber()+"'";
		// Connection con=null;
		// try {
		// con=DbUtil.getConnection(Class.forName("oracle.jdbc.driver.OracleDriver"),
		// "jdbc:oracle:thin:@127.0.0.1:1521:csmisdb", "cqgsjc412", "csmis");
		// } catch (ClassNotFoundException e1) {
		// e1.printStackTrace();
		// } catch (Exception e1) {
		// e1.printStackTrace();
		// }
		// if(con!=null){
		// System.out.println(con.toString());
		// }
		//

		Connection con = null;
		try {
			con = DbUtil.getConnection(
					Class.forName("oracle.jdbc.driver.OracleDriver"),
					"jdbc:oracle:thin:@//98.12.102.73:1521/cqsthxqf",
					"wsbs_ysq", "wsbs_ysq");
		} catch (ClassNotFoundException e1) {
			e1.printStackTrace();
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		Statement st = null;
		ResultSet rs = null;
		List<CaseCheckEnterprice> ll = new ArrayList<CaseCheckEnterprice>();
		if (con != null) {
			String sql = "select t.* from hx_dj.dj_nsrxx t where t.NSRSBH='"
					+ source.getTaxpayerNumber() + "'";
			try {
				st = con.createStatement();
				rs = st.executeQuery(sql);

				while (rs.next()) {
					CaseCheckEnterprice po = new CaseCheckEnterprice();
					try {
						po.setTaxpayerNumber(rs.getString("NSRSBH"));
						po.setCertificateNumber(rs
								.getString("FDDBRHFZRHYZSFZJHM"));
						po.setIndustryName(rs.getString("JYFW"));
						po.setRegisterAddress(rs.getString("SCJYDZ"));// 经营地址
						po.setTaxEnterprice(rs.getString("NSRMC"));// 纳税人名称
						po.setLegalPerson(rs.getString("FDDBRHFZRHYZXM"));// 法人
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					ll.add(po);
				}

			} catch (SQLException e) {
				e.printStackTrace();
			} finally {
				try {
					if (rs != null)
						rs.close();
					if (st != null)
						st.close();
					if (con != null)
						con.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
				}

			}

		}

		// //DbUtil.getConnection(driver, dbUrl, userName, userPwd)
		// List<CaseCheckEnterprice> l=DbUtil.executeSqlQuery(sql, new
		// ISQLMapper(){
		//
		// @Override
		// public Object fromSQLQuery(ResultSet rs, int num) {
		// CaseCheckEnterprice po=new CaseCheckEnterprice();
		// try {
		// po.setTaxpayerNumber(rs.getString("NSRSBH"));
		// po.setCertificateNumber(rs.getString("FDDBRHFZRHYZSFZJHM"));
		// po.setIndustryName(rs.getString("JYFW"));
		// po.setRegisterAddress(rs.getString("SCJYDZ"));//经营地址
		// po.setTaxEnterprice(rs.getString("NSRMC"));//纳税人名称
		// po.setLegalPerson(rs.getString("FDDBRHFZRHYZXM"));//法人
		// } catch (SQLException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }
		//
		// return po;
		// }});

		if (ll != null && ll.size() > 0) {
			this.po = ll.get(0);
		} else {

		}

		return "openNsrPage";
	}

	/*
	 * 提请审批页面
	 */
	public String drawApprovePage() throws AppException {
		String caseId = this.getParameter("caseId");
		CaseSource source = (CaseSource) this.baselogic.getPOByPk(
				"com.ce.cases.source.dao.po.CaseSource", caseId);
		List drawApprList = this.baselogic
				.searchByHql("From CaseSourceDrawApprove po where po.caseId='"
						+ caseId + "' and po.vcDelFlag=0");
		if (!drawApprList.isEmpty()) {
			drawAppr = (CaseSourceDrawApprove) drawApprList.get(0);
		} else {
			drawAppr = new CaseSourceDrawApprove();
			drawAppr.setCaseId(caseId);
			drawAppr.setCaseFromNum(source.getCaseFromNum());
			drawAppr.setCaseFromName(source.getCaseFromName());
			drawAppr.setTaxpayer(source.getInvolvedEnterprice());
			drawAppr.setTaxpayerNumber(source.getTaxpayerNumber());
			drawAppr.setDrawDept(User.getUserOrgName());
		}
		return "drawApprovePage";
	}

	/*
	 * 提请审批操作
	 */
	public String drawApprove() throws AppException {
		try {
			// 修改审批表
			if (StringUtil.isNotBlank(drawAppr.getVcId())) {
				drawAppr.setVcDelFlag(0);
				this.baselogic.updatePo(drawAppr);
			} else {// 添加审批表
				drawAppr.setVcId(GeneratorUUID.generateUUID());
				drawAppr.setVcDelFlag(0);
				drawAppr.setDrawDeptId(User.getUserOrgId());
				this.baselogic.addPo(drawAppr);
			}
		} catch (AppException e) {
			LogUtil.logError(e);
			return this.returnInfoForJS(false,
					e.getMessage().replaceAll("'|\\n", " "));
		}
		return this.returnInfoForJS(true, "提请审批操作成功!");
	}

	@SuppressWarnings("unchecked")
	public String viewHearResult() throws AppException {
		String caseId = this.getSelectId();
		List<CaseSourceHear> hearList = (List<CaseSourceHear>) this.baselogic
				.searchByHql("From CaseSourceHear po where po.caseId='"
						+ caseId + "'");
		CaseSourceHear hearPo = null;
		if (!hearList.isEmpty())
			hearPo = hearList.get(0);
		this.setAttribute("po", hearPo);
		return "viewHearResult";
	}

	public CaseSourceApprove getAppr() {
		return appr;
	}

	public void setAppr(CaseSourceApprove appr) {
		this.appr = appr;
	}

	public CaseSourceDrawApprove getDrawAppr() {
		return drawAppr;
	}

	public void setDrawAppr(CaseSourceDrawApprove drawAppr) {
		this.drawAppr = drawAppr;
	}

}
